package com.briup.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.domain.Category;
import com.briup.domain.extend.CategoryExtend;
import com.briup.resuit.Result;
import com.briup.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "栏目模块")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @ApiOperation("新增栏目")
    @PostMapping("/save")
    public Result save(@RequestBody  Category category) {
        categoryService.insertCategory(category);
        return Result.success("新增成功");
    }
    @ApiOperation("根据id查询栏目信息")
    @GetMapping("/queryById/{id}")
    public Result getCategoryById(@PathVariable int id) {
        return Result.success(categoryService.selectOneById(id));
    }
    @ApiOperation("更新栏目")
    @PutMapping("/update")
    public Result update(@RequestBody Category category) {
        categoryService.updateCategory(category);
        return Result.success("修改成功");
    }
    @ApiOperation("根据id删除栏目")
    @DeleteMapping("/deleteByBatch/{id}")
    public Result deleteById(@PathVariable int id) {
        categoryService.deleteCategory(id);
        return Result.success("删除成功");
    }
    @ApiOperation( "批量删除栏目")
    @DeleteMapping("/deleteByIdAll/{ids}")
    public Result deleteCategoryInBatch(@PathVariable("ids") List<Integer> ids) {
        categoryService.deleteInBatch(ids);
        return Result.success("删除成功");
    }
    @ApiOperation("分页查询所有栏目")
    @GetMapping("/query")
    public Result query(@RequestParam Integer pageNum,@RequestParam Integer pageSize,
                        Integer parentId) {
        return Result.success(categoryService.selectAll(pageNum,pageSize,parentId));
    }
    @ApiOperation("查询所有1级栏目(含2级)")
    @GetMapping("/queryAllParent")
    public Result queryAllParent(){
        List<CategoryExtend> categoryExtends = categoryService.queryAllParent();
        return Result.success(categoryExtends);
    }
    @ApiOperation("获取所有父栏目")
    @GetMapping("/queryAllOneLevel")
    public Result queryAllParentWithoutTwo(){
        List<Category> list = categoryService.queryAllOneLevel();
        return Result.success(list);
    }
}
